package
{
	import cuckoo.games.knickers.Ball;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	public class Knickers extends Sprite
	{
		private var m_ball:Ball;
		public function Knickers()
		{
			// 支持 autoOrient
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			m_ball = new Ball();
			m_ball.x = Math.random() * stage.stageWidth;
			m_ball.y = Math.random() * stage.stageHeight;
			addChild(m_ball);
			addEventListener(Event.ENTER_FRAME,onFrame);
			
			stage.frameRate = 40;
		}
		
		private var m_speedX:Number = 5;
		private var m_speedY:Number = 5;
		private function onFrame(e:Event):void
		{
			if(m_ball.x < 0 || m_ball.x > stage.stageWidth)
			{
				m_speedX *= -1;
			}
			
			if(m_ball.y < 0 || m_ball.y > stage.stageHeight)
			{
				m_speedY *= -1;
			}
			
			m_ball.x += m_speedX;
			m_ball.y += m_speedY;
		}
	}
}